package com.ruoyi.project.bas.traycode.controller;

import java.util.List;

import com.ruoyi.project.bas.traycodehead.domain.BasTraycodeHead;
import com.ruoyi.project.bas.traycodehead.service.IBasTraycodeHeadService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.bas.traycode.domain.BasTraycode;
import com.ruoyi.project.bas.traycode.service.IBasTraycodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 托盘条码信息Controller
 * 
 * @author ruoyi
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/bas/traycode")
public class BasTraycodeController extends BaseController
{
    private String prefix = "bas/traycode";

    @Autowired
    private IBasTraycodeService basTraycodeService;
    @Autowired
    private IBasTraycodeHeadService basTraycodeHeadService;

    @GetMapping()
    public String traycode()
    {
        return prefix + "/traycode";
    }

    /**
     * 查询托盘条码信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasTraycode basTraycode)
    {
        startPage();
        List<BasTraycode> list = basTraycodeService.selectBasTraycodeList(basTraycode);
        return getDataTable(list);
    }

    /**
     * 导出托盘条码信息列表
     */
    @Log(title = "托盘条码信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasTraycode basTraycode)
    {
        List<BasTraycode> list = basTraycodeService.selectBasTraycodeList(basTraycode);
        ExcelUtil<BasTraycode> util = new ExcelUtil<BasTraycode>(BasTraycode.class);
        return util.exportExcel(list, "托盘条码信息数据");
    }

    /**
     * 新增托盘条码信息
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        BasTraycodeHead basTraycodeHead=new BasTraycodeHead();
        basTraycodeHead.settStatus("Y");
        List<BasTraycodeHead> traycodeHeadList=basTraycodeHeadService.selectBasTraycodeHeadList(basTraycodeHead);
        modelMap.put("traycodeHeadList",traycodeHeadList);
        return prefix + "/add";
    }

    /**
     * 新增保存托盘条码信息
     */
    @Log(title = "托盘条码信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasTraycode basTraycode)
    {
        return toAjax(basTraycodeService.insertBasTraycode(basTraycode));
    }

    /**
     * 修改托盘条码信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        BasTraycode basTraycode = basTraycodeService.selectBasTraycodeById(id);
        mmap.put("basTraycode", basTraycode);
        return prefix + "/edit";
    }

    /**
     * 修改保存托盘条码信息
     */
    @Log(title = "托盘条码信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasTraycode basTraycode)
    {
        return toAjax(basTraycodeService.updateBasTraycode(basTraycode));
    }

    /**
     * 删除托盘条码信息
     */
    @Log(title = "托盘条码信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basTraycodeService.deleteBasTraycodeByIds(ids));
    }


    @RequestMapping("selectCount")
    @ResponseBody
    public int selectCount(String tHead){
        return basTraycodeService.selectHeadCount(tHead);
    }

    @RequestMapping("/updateStatus")
    @ResponseBody
    public int updateStatus(String trayCode){
        basTraycodeService.updateStatus(trayCode);
        return 1;
    }


}
